package cn.rengy.auth.entity.principal;

import lombok.ToString;

import java.io.Serializable;
import java.security.Principal;
@ToString
public class Identity implements Principal, Serializable{
	
	private static final long serialVersionUID = 1L;
	private Long userId;
	/**租户id**/
    private Long tenantId;
	private String sessionId;
	private Long authId;
	private String clientId;
	private String name;

	public boolean equals(Object another) {
		if (another == null) {
			return false;
		}
        if (this == another) {
        	return true;
        }
        if (!(another instanceof Principal)) {
        	return false;
        }
        Identity that = (Identity) another;
        if (this.getUserId().equals(that.getUserId())) {
        	return true;
        }
        return false;
    }
 
    public int hashCode() {
        return getUserId().hashCode();
    }

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		if(name!=null){
			return name;
		}
		return userId ==null?"null": userId.toString();
	}

	public Long getAuthId() {
		return authId;
	}

	public void setAuthId(Long authId) {
		this.authId = authId;
	}

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

    public Long getTenantId() {
        return tenantId;
    }

    public void setTenantId(Long tenantId) {
        this.tenantId = tenantId;
    }
}
